local skel = fk.CreateSkill {
  name = "lb__tianqi",
}

Fk:loadTranslationTable {
  ["lb__tianqi"] = "天欺",
  --[":lb__tianqi"] = "每回合限一次，当你攻击范围内的其他角色造成伤害时，你可以将伤害来源改为你，然后你可以复原武将牌。",
  --9.23
  --[":lb__tianqi"] = "每回合限一次，当你攻击范围内的其他角色造成伤害时，你可以将伤害来源改为你，若为你本轮首次发动，你可以复原武将牌。",
  --10.5
  [":lb__tianqi"] = "每回合限一次，当你攻击范围内的角色受到伤害时，你可以将伤害来源改为你，若为你本轮首次发动，你可以复原武将牌。",

  ["#lb__tianqi"] = "天欺：%dest 即将受到%arg点%arg2伤害，你可以将伤害来源改为你，然后你可以复原武将牌",
  ["#lb__tianqi_reset"] = "天欺：你可以复原武将牌",

  ["$lb__tianqi1"] = "一人传虚，万人传实。",
  ["$lb__tianqi2"] = "轻轻挠一下就受不了了？",
}

skel:addEffect(fk.DetermineDamageInflicted, {
  priority = 2,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) -- and data.from and data.from ~= player 
    and not data.prevented
    and player:inMyAttackRange(data.to) and player:usedSkillTimes(skel.name) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player,
      { skill_name = skel.name, 
      prompt = "#lb__tianqi::" .. data.to.id .. ":" .. data.damage .. ":" .. Fk:getDamageNatureName(data.damageType) })
  end,
  on_use = function(self, event, target, player, data)
    --[[
    if not data.chain then
      data.extra_data = data.extra_data or {}
      data.extra_data.lb__tianqi = player.id
    end
    --]]
    data.from = player
    if player:isAlive() and player:usedSkillTimes(skel.name, Player.HistoryRound) == 1 and player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#lb__tianqi_reset" }) then
      player:reset()
    end
  end,
})
--[[
skel:addEffect(fk.DamageFinished, {
  global = true,
  can_refresh = function(self, event, target, player, data)
    return data.extra_data and data.extra_data.lb__tianqi
        and data.extra_data.lb__tianqi == player.id
        and data.beginnerOfTheDamage and data.chain_table
  end,
  on_refresh = function(self, event, target, player, data)
    data.chain_table =
        table.filter(player.room:getOtherPlayers(data.to), function(p)
          return p.chained
        end)
  end,
})
--]]
--[[
skel:addEffect(fk.PreDamage, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target ~= player and player:inMyAttackRange(target) and player:usedSkillTimes(skel.name) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player,{skill_name = skel.name, prompt = "#lb__tianqi::"..target.id})
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if not damageData.chain then
      damageData.beginnerOfTheDamage = true
      damageData.chain_table = table.filter(room:getOtherPlayers(damageData.to), function(p)
        return p.chained
      end)
    end
    local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if e then
      local use = e.data
      local from = room:getPlayerById(use.extra_data.huoshou)
      data.from = not from.dead and from or nil
    end
  end,
})
--]]
return skel
